package cn.shutdown.farm.action;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import sy.action.BaseAction;
import cn.shutdown.farm.model.Plant;
import cn.shutdown.farm.service.PlantServiceI;

import com.opensymphony.xwork2.Action;

@Controller
public class PlantAction extends BaseAction implements Action {

	private String id;
	private String name;
	private String level;
	private Long seedPrice;
	private Long fruitPrice;
	private Integer fruitNum;
	private Long ripeTime;
	private Long exp;
	private Date createTime;
	private Plant plant;
	
	@Autowired
	private PlantServiceI plantService;

	public String addPlant() {
		return "addPlant";
	}
	
	public void update(){
		plant = new Plant(id, name, level, seedPrice, fruitPrice, fruitNum, ripeTime, exp, new Date());
		plantService.update(plant);
		super.writeJson(plant);
	}
	
	public void save() {
		plant = new Plant(id, name, level, seedPrice, fruitPrice, fruitNum, ripeTime, exp, new Date());
		plantService.create(plant);
		super.writeJson(plant);
	}
	
	public void list(){
		List<Plant> plantList = plantService.findAll();
		super.writeJson(plantList);
	}

	public String helloworld() {
		return "helloworld";
	}
	
	public void delete(){
		plantService.delete(id);
		Map<String,Object> result = new HashMap<String,Object>();
		result.put("success", true);
		super.writeJson(result);
	}

	@Override
	public String execute() throws Exception {
		return null;
	}

	public Plant getPlant() {
		return plant;
	}

	public void setPlant(Plant plant) {
		this.plant = plant;
	}

	public PlantServiceI getPlantService() {
		return plantService;
	}

	public void setPlantService(PlantServiceI plantService) {
		this.plantService = plantService;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public Date getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getLevel() {
		return level;
	}

	public void setLevel(String level) {
		this.level = level;
	}

	public Long getSeedPrice() {
		return seedPrice;
	}

	public void setSeedPrice(Long seedPrice) {
		this.seedPrice = seedPrice;
	}

	public Long getFruitPrice() {
		return fruitPrice;
	}

	public void setFruitPrice(Long fruitPrice) {
		this.fruitPrice = fruitPrice;
	}

	public Integer getFruitNum() {
		return fruitNum;
	}

	public void setFruitNum(Integer fruitNum) {
		this.fruitNum = fruitNum;
	}

	public Long getRipeTime() {
		return ripeTime;
	}

	public void setRipeTime(Long ripeTime) {
		this.ripeTime = ripeTime;
	}

	public Long getExp() {
		return exp;
	}

	public void setExp(Long exp) {
		this.exp = exp;
	}
	
}
